<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link href="${pageContext.request.contextPath}/static/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/style.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/Widget/zTree/css/zTreeStyle/zTreeStyle.css"
          type="text/css">
    <link href="${pageContext.request.contextPath}/static/Widget/icheck/icheck.css" rel="stylesheet" type="text/css"/>
    <!--[if IE 7]>
		  <%--<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/font-awesome-ie7.min.css" />--%>
		<![endif]-->
    <!--[if lte IE 8]>
		  <%--<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/ace-ie.min.css" />--%>
		<![endif]-->
    <script type="text/javascript">
        window.jQuery || document.write("<script src='${pageContext.request.contextPath}/static/assets/js/jquery-2.0.3.min.js'>" + "<" + "/script>");
    </script>
    <script type="text/javascript">
        if ("ontouchend" in document) document.write("<script src='${pageContext.request.contextPath}/static/assets/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
    </script>
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.9.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/assets/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/assets/js/typeahead-bs2.min.js"></script>
    <!-- page specific plugin scripts -->
    <script src="${pageContext.request.contextPath}/static/assets/js/jquery.dataTables.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/H-ui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/H-ui.admin.js"></script>
    <script src="${pageContext.request.contextPath}/static/assets/layer/layer.js" type="text/javascript"></script>
    <script src="${pageContext.request.contextPath}/static/assets/laydate/laydate.js" type="text/javascript"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/Widget/zTree/js/jquery.ztree.all-3.5.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/lrtk.js" type="text/javascript"></script>
    <title>产品列表</title>
</head>
<body>
<div class=" page-content clearfix">
    <div id="products_style">
        <div class="search_style">
            <ul class="search_content clearfix">
                <form action="${pageContext.request.contextPath}/product/findproduct" method="post">
                <li><label class="l_f">产品名称</label>
                    <input <%--id="product_id"--%> name="product_name" type="text" class="text_add" placeholder="产品名称" style=" width:250px"/></li>
                <li style="width:90px;">
                    <button type="button" class="btn_search" <%-- onclick="findproduct()"--%>><i class="icon-search"></i>查询</button>
                </li>
                </form>
            </ul>
        </div>

        <div class="border clearfix">
       <span class="l_f">
        <a <%--href="${pageContext.request.contextPath}/product/getpicture"--%>
                href="javascript:ovid()" id="product_add" onclick="productlist_add()"
                title="添加商品" class="btn btn-warning Order_form"><i class="icon-plus"></i>添加商品</a>
       </span>
           <%-- <span class="r_f">共：<b>40</b>件商品</span>--%>
        </div>
        <!--产品列表展示-->
        <div class="h_products_list clearfix" id="products_list">
            <!--       <div id="scrollsidebar" class="left_Treeview">
                    <div class="show_btn" id="rightArrow"><span></span></div>
                    <div class="widget-box side_content" >
                     <div class="side_title"><a title="隐藏" class="close_btn"><span></span></a></div>
                     <div class="side_list"><div class="widget-header header-color-green2"><h4 class="lighter smaller">产品类型列表</h4></div>
                     <div class="widget-body">
                      <div class="widget-main padding-8"><div id="treeDemo" class="ztree"></div></div>
                    </div>
                   </div>
                  </div>  -->
        </div>
        <div class="table_menu_list" id="testIframe">
            <table class="table table-striped table-bordered table-hover" id="sample-table">
                <thead>
                <tr>
                    <th width="25px"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
                    <th width="80px">产品编号</th>
                    <th width="250px">产品名称</th>
                    <th width="100px">原价格</th>
                    <th width="100px">现价</th>
                    <th width="100px">所属地区/国家</th>
                    <th width="180px">加入时间</th>
                    <th width="80px">审核状态</th>
                    <th width="70px">状态</th>
                    <th width="200px">操作</th>
                </tr>
                </thead>
                <tbody>

                <c:forEach items="${productList}" var="product" varStatus="i">
                <tr>
                    <td width="25px"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></td>
                    <td width="80px">${product.product_id} <%--45631--%></td>
                    <td width="220px"><u style="cursor:pointer" class="text-primary" onclick="">
                         ${product.product_name}   <%--小米 Max 全网通 高配版 3GB内存
                        64GB ROM 金色 移动联通电信4G手机Y--%></u></td>
                    <td width="100px">${product.product_s_price}</td>
                    <td width="100px">${product.product_price}</td>
                    <td width="150px">法国</td>
                    <td width="180px"><fmt:formatDate value="${product.product_create_time}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
                    <%--<td width="180px">2014-6-11 11:11:42</td>--%>
                    <td class="text-l">通过</td>
                    <td class="td-status"><span class="label label-success radius">已启用</span></td>
                    <td class="td-manage">
                        <a onClick="member_stop(this,'10001')" href="javascript:;" title="停用"
                           class="btn btn-xs btn-success"><i class="icon-ok bigger-120"></i></a>
                        <a title="编辑" onclick="member_edit('${product.product_id}')" href="javascript:;"
                           class="btn btn-xs btn-info"><i class="icon-edit bigger-120"></i></a>
                        <a title="删除" <%--href="javascript:;" onclick="member_del(this,'1')"--%>
                                href="${pageContext.request.contextPath}/product/delproduct?product_id=${product.product_id}"
                           class="btn btn-xs btn-warning"><i class="icon-trash  bigger-120"></i></a>
                    </td>
                </tr>
                </c:forEach>

                </tbody>
            </table>
        </div>
    </div>
</div>
</div>

</body>
<%--编辑--%>
<div class="add_menber" id="edit_menber_style" style="display:none">

    <ul class=" page-content">
        <li><label class="label_name">产品编号：</label><span class="add_name"><input value="${product1.product_id}" name="product_id"
                                                                                 type="text"
                                                                                 class="text_add" disabled="true"/></span>
            <div class="prompt r_f"></div>
        </li>

        <li><label class="label_name">产品名称：</label><span class="add_name"><input value="${product1.product_name}"  name="product_name2" type="text"
                                                                                 class="text_add"/></span>
            <div class="prompt r_f"></div>
        </li>
        <li><label class="label_name">原&nbsp;&nbsp;价&nbsp;&nbsp;格：</label><span class="add_name"><input value="${product1.product_s_price}" name="product_s_price" type="text"
                                                                                                        class="text_add"/></span>
            <div class="prompt r_f"></div>
        </li>
        <li><label class="label_name">现&nbsp;&nbsp;&nbsp;&nbsp;价：</label><span class="add_name"><input value="${product1.product_price}"  name="product_price" type="text"
                                                                                                       class="text_add"/></span>
            <div class="prompt r_f"></div>
        </li>

    </ul>
</div>
<%--添加--%>
<div class="add_menber" id="add_menber_style" style="display:none">

    <ul class=" page-content">
        <li><label class="label_name">产品编号：</label><span class="add_name"><input value="" name="product_id1"
                                                                                 type="text"
                                                                                 class="text_add"/></span>
            <div class="prompt r_f"></div>
        </li>
        <li><label class="label_name">产品名称：</label><span class="add_name"><input value=""  name="product_name1" type="text"
                                                                                 class="text_add"/></span>
            <div class="prompt r_f"></div>
        </li>
        <li><label class="label_name">原&nbsp;&nbsp;价&nbsp;&nbsp;格：</label><span class="add_name"><input value="" name="product_s_price1" type="text"
                                                                                                        class="text_add"/></span>
            <div class="prompt r_f"></div>
        </li>
        <li><label class="label_name">现&nbsp;&nbsp;&nbsp;&nbsp;价：</label><span class="add_name"><input value=""  name="product_price1" type="text"
                                                                                                       class="text_add"/></span>
            <div class="prompt r_f"></div>
        </li>
    </ul>
</div>
</html>
<script>
    function finds(){
        var product_id =$("#product_id").val();
        if(product_id==""){
            alert("编号不能为空！");
            return false;
        }
        else
        {
            $.ajax({
                type:'post',
                url:'finds',
                dataType:"json",//注意使用的是打他dataType，而不是Content-Type
                async: true,
                data:{product_id:product_id},
                success:function(data){
                    if(data==null){
                        alert("没有这个用户！")
                    }
                    else{
                        window.location.href ="Products_List.jsp";
                    }
                }
            });
        }
    }
</script>
<script>
    jQuery(function ($) {
        var oTable1 = $('#sample-table').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable": false, "aTargets": [0, 2, 3, 4, 5, 8, 9]}// 制定列不参与排序
            ]
        });


        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });


        $('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});

        function tooltip_placement(context, source) {
            var $source = $(source);
            var $parent = $source.closest('table')
            var off1 = $parent.offset();
            var w1 = $parent.width();

            var off2 = $source.offset();
            var w2 = $source.width();

            if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) return 'right';
            return 'left';
        }
    });
    laydate({
        elem: '#start',
        event: 'focus'
    });
    $(function () {
        $("#products_style").fix({
            float: 'left',
            //minStatue : true,
            skin: 'green',
            durationTime: false,
            spacingw: 30,//设置隐藏时的距离
            spacingh: 260,//设置显示时间距
        });
    });
<%--</script>
<script type="text/javascript">--%>


    /*******树状图*******/
    var setting = {
        view: {
            dblClickExpand: false,
            showLine: false,
            selectedMulti: false
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: ""
            }
        },
        callback: {
            beforeClick: function (treeId, treeNode) {
                var zTree = $.fn.zTree.getZTreeObj("tree");
                if (treeNode.isParent) {
                    zTree.expandNode(treeNode);
                    return false;
                } else {
                    demoIframe.attr("src", treeNode.file + ".jsp");
                    return true;
                }
            }
        }
    };

    var code;

    function showCode(str) {
        if (!code) code = $("#code");
        code.empty();
        code.append("<li>" + str + "</li>");
    }

    $(document).ready(function () {
        var t = $("#treeDemo");
        t = $.fn.zTree.init(t, setting, zNodes);
        demoIframe = $("#testIframe");
        demoIframe.bind("load", loadReady);
        var zTree = $.fn.zTree.getZTreeObj("tree");
        zTree.selectNode(zTree.getNodeByParam("id", '11'));
    });

    /*产品-停用*/
    function member_stop(obj, id) {
        layer.confirm('确认要停用吗？', function (index) {
            $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs " onClick="member_start(this,id)" href="javascript:;" title="启用"><i class="icon-ok bigger-120"></i></a>');
            $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
            $(obj).remove();
            layer.msg('已停用!', {icon: 5, time: 1000});
        });
    }

    /*产品-启用*/
    function member_start(obj, id) {
        layer.confirm('确认要启用吗？', function (index) {
            $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs btn-success" onClick="member_stop(this,id)" href="javascript:;" title="停用"><i class="icon-ok bigger-120"></i></a>');
            $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
            $(obj).remove();
            layer.msg('已启用!', {icon: 6, time: 1000});
        });
    }

    /*产品-编辑*/
    /*function member_edit(title, url, id, w, h) {
        layer_show(title, url, w, h);
    }*/
    function member_edit(product_id) {
        //alert(product_id);
        var pathName=document.location.pathname;
        console.log("pathName="+pathName);
        var index=pathName.substr(1).indexOf("/");
        var result=pathName.substr(0,index+1);
        console.log(result);
        //alert(result);
        $.ajax({
            url:result+"/product/edit1",
            type:"get",
            data:{product_id:product_id},
            dataType:"json",
            success:function (data) {
                if (data.success) {
                    layer.open({
                        type: 1,
                        title: '修改商品信息',
                        maxmin: true,
                        shadeClose: false, //点击遮罩关闭层
                        area: ['800px', ''],
                        content: $('#edit_menber_style'),
                        btn: ['提交', '取消'],
                        yes: function (index, layero) {
                            var num = 0;
                            var str = "";
                            $("#edit_menber_style input[type$='text']").each(function (n) {

                                //alert($(this).val());
                                //alert(n);
                                if ($(this).val() == "") {

                                    layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                                        title: '提示框',
                                        icon: 0,
                                    });
                                    num++;
                                    return false;
                                }
                            });

                            var product_id=$('input[name="product_id"]').val();
                            console.log("product_id="+product_id);

                            var product_name=$('input[name="product_name2"]').val();
                            console.log("product_name="+product_name);

                            var product_s_price=$('input[name="product_s_price"]').val();
                            console.log("product_s_price="+product_s_price);

                            var product_price=$('input[name="product_price"]').val();
                            console.log("product_price="+product_price);

                            if (num > 0) {
                                return false;
                            } else {
                                $.ajax({
                                    url:result+"/product/updateproduct",
                                    type:"get",
                                    data:{
                                        product_id:product_id,
                                        product_name:product_name,
                                        product_s_price:product_s_price,
                                        /*member_gender:zsex,*/
                                        product_price:product_price
                                    },
                                    dataType:"json",
                                    success:function (data) {
                                        if (data.success) {

                                            //alert(num);
                                            layer.alert('修改成功！', {
                                                title: '提示框',
                                                icon: 1,
                                            });

                                            layer.close(index);


                                        }else {
                                            alert("修改失败");
                                        }
                                    }
                                })


                            }
                        }
                    });
                }else{
                    alert("修改失败");
                }
            }
        })
    }

    function productlist_add() {
        var pathName=document.location.pathname;
        console.log("pathName="+pathName);
        var index=pathName.substr(1).indexOf("/");
        var result=pathName.substr(0,index+1);
        console.log(result);
        //alert(result);
        layer.open({
            type: 1,
            title: '添加信息',
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area: ['700px', ''],
            content: $('#add_menber_style'),
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var num = 0;
                var str = "";
                $("#add_menber_style input[type$='text']").each(function (n) {
                    //alert($(this).val());
                    //alert(n);
                    if ($(this).val() == "") {

                        layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        });
                        num++;
                        return false;
                    }
                });

                var product_id=$('input[name="product_id1"]').val();
                console.log("product_id="+product_id);
                var product_name=$('input[name="product_name1"]').val();
                console.log("product_name="+product_name);
                var product_s_price=$('input[name="product_s_price1"]').val();
                console.log("product_s_price="+product_s_price);
                var product_price=$('input[name="product_price1"]').val();
                console.log("product_price="+product_price);
                if (num > 0) {
                    return false;
                } else {
                    $.ajax({
                        url:result+"/product/addproduct",
                        type:"get",
                        data:{
                            product_id:product_id,
                            product_name:product_name,
                            product_s_price:product_s_price,
                            product_price:product_price},
                        dataType:"json",
                        success:function (data) {
                            if (data.success) {
                                //alert(num);
                                layer.alert('添加成功！', {
                                    title: '提示框',
                                    icon: 1,
                                });
                                layer.close(index);
                            }else {
                                alert("添加失败");
                            }
                        }
                    })


                }
            }
        });

    }

    /*产品-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
        });
    }

    //面包屑返回值
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.iframeAuto(index);
    $('.Order_form').on('click', function () {
        var cname = $(this).attr("title");
        var chref = $(this).attr("href");
        var cnames = parent.$('.Current_page').html();
        var herf = parent.$("#iframe").attr("src");
        parent.$('#parentIframe').html(cname);
        parent.$('#iframe').attr("src", chref).ready();
        parent.$('#parentIframe').css("display", "inline-block");
        parent.$('.Current_page').attr({"name": herf, "href": "javascript:void(0)"}).css({
            "color": "#4c8fbd",
            "cursor": "pointer"
        });
        //parent.$('.Current_page').html("<a href='javascript:void(0)' name="+herf+" class='iframeurl'>" + cnames + "</a>");
        parent.layer.close(index);

    });
</script>
